<template lang="html">
  <div class="news-index">
    <div class="swiper-hot">
      <div class="sh-head">
        <div class="titles">
          <h3>Major Topic</h3>
          <p>Wish you good mood every day!</p>
        </div>
        <div class="avatar">
          <img class="max" :src="getUserInfo().headimgurl" alt="">
        </div>
      </div>

      <div class="">
        <div class="swiper-banner">
          <swiper ref="mySwiper" :options="swiperOption" @slideChange="swiperCallback">
            <swiper-slide class="slide-1" v-for="(item, idx) in hotList" :key="idx">
              <img class="max" @click="routeTo('/modules/news/detail?id='+item.id)" :src="item.photo">
              <div class="slide-zan">
                <img class="max" v-if="item.is_like" src="/static/modules/news/information_icon_like_press@2x.png">
                <img class="max" v-else src="/static/modules/news/information_icon_like_no r@2x.png">
              </div>
            </swiper-slide>
            <div class="swiper-pagination" slot="pagination"></div>
          </swiper>
        </div>
        <div class="swiper-card" v-if="hotList && hotList.length != 0">
          <Card type="list" :detail="hotList[activeIndex]" />
        </div>
      </div>
    </div>
    <div class="recommend">
      <div class="head">
        Recommend
      </div>
      <div class="recommend-container">
        <ul :style="'width:'+recommendList.length*4.8+'rem'">
          <li v-for="i in recommendList" @click="routeTo('/modules/news/detail?id='+i.id)">
            <div class="pic">
              <img class="max" :src="i.photo">
            </div>
            <div class="title">
              {{ i.title }}
            </div>
          </li>
        </ul>
      </div>
    </div>
  </div>
</template>

<script>
import Card from './components/Card'
import { getNewsList } from '@/api/modules/news'
import 'swiper/dist/css/swiper.css'
import { swiper, swiperSlide } from 'vue-awesome-swiper'
export default {
  components: {
    Card,
    swiper,
    swiperSlide
  },
  data() {
    return {
      hotList: [],
      recommendList: [],
      activeIndex: 0,
      swiperOption: {
        effect: 'flip',
        grabCursor: true,
        pagination: {
          el: '.swiper-pagination'
        },
      }
    }
  },
  created() {
    this.getHotNewsList();
    this.getRecommendNewsList();
  },
  methods: {
    // 热门
    getHotNewsList() {
      getNewsList({
        uid: this.getUserInfo().id,
        art_type: 0
      }).then(res=>{
        this.hotList = res.data;
      })
    },
    // 推荐
    getRecommendNewsList() {
      getNewsList({
        uid: this.getUserInfo().id,
        art_type: 1
      }).then(res=>{
        this.recommendList = res.data;
      })
    },
    swiperCallback() {
      this.activeIndex = this.$refs.mySwiper.swiper.realIndex
    }
  }
}
</script>

<style lang="scss" scoped>
.news-index{
  background-color: #fff;
}
.swiper-container {
  width: 100%;

}
.swiper-pagination{
  bottom: -2.6rem;
}
.swiper-card{
  padding: 0 .5rem;
}
.swiper-slide {
  background-position: 50%!important;
  background-size: cover!important;
  width: 100%!important;
  height: 100%;
  position: relative;
  img{
    border-radius: .4rem;
  }
  .slide-zan{
    position: absolute;
    right: 0;
    top: 0;
    width: 2.53rem;
    height: 2.53rem;
  }
}

.swiper-hot{
  .sh-head{
    overflow: hidden;
    margin: 0 .4rem;
    padding-top: .4rem;
    .titles{
      float: left;
      h3{
        font-size: .4rem;
        padding-top: .2rem;
      }
      p{
        font-size: .3rem;
        color: #BBBBBB;
      }
    }
    .avatar{
      float: right;
      width: 1.4rem;
      img{
        border-radius: 50%;
      }
    }
  }
}
.swiper-banner{
  width: 90%;
  margin: 0 auto;
  margin-top: .6rem;
  border-radius: .4rem;
}
.recommend{
  margin-top: 1.4rem;
  .head{
    margin-left: .6rem;
    position: relative;
    padding-left: .4rem;
    margin-bottom: .4rem;
    font-size: .4rem;
    font-weight: 600;
    &::before{
      position: absolute;
      content: "";
      left: 0;
      top: 0;
      width: 5px;
      height: 100%;
      border-radius: .6rem;
      background-color: #4F80FF;
    }
  }
  .recommend-container{
    overflow: scroll;
    ul{
      margin-left: .6rem;
      padding-right: .4rem;
    }
    li{
      width: 4rem;
      float: left;
      margin-right: .5rem;
      background-color: #fff;
      box-shadow:0px 0px 23px 0px rgba(222,222,223,1);
      border-radius: .3rem;
      overflow: hidden;
      margin-bottom: 1rem;
      .pic{
        width: 4rem;
        height: 4rem;
        img{
          width: 100%;
          height: 100%;
        }
      }
      .title{
        padding: .3rem .1rem;
        overflow:hidden;
        text-overflow:ellipsis;
        white-space:nowrap;
      }
    }
  }
}
</style>
